Const sColumns As String = "1月|2月|3月|4月|5月|6月"                             '
Const nClassify As Integer = 2                            '分类名所在列
Const iCollect As Integer = 3                             '汇总数据所在列


Sub 逆透视汇总()
    Dim index As Object                                   '索引
    Set index = CreateObject("Scripting.Dictionary")
    Dim DataTable(1 To 5, 1 To 11)                     '数据表
    Dim tRow%, tCol%                                      '数据表行,数据表列
    Dim aRng(), x%, nRow%                                 '数据选区,循环,行号

    aRng = Range("a2:d" & Range("a65535").End(xlUp).Row)
    For x = 1 To UBound(aRng)
        tCol = Application.Match(aRng(x, nClassify), Split(sColumns, "|"), 0) + 1
        If index.exists(aRng(x, 1)) Then
            tRow = index(aRng(x, 1))
            DataTable(tRow, tCol) = DataTable(tRow, tCol) + aRng(x, iCollect)
        Else
            nRow = nRow + 1
            index(aRng(x, 1)) = nRow
            DataTable(nRow, 1) = aRng(x, 1)
            DataTable(nRow, tCol) = aRng(x, iCollect)
            
        End If
    Next x
    Stop
    'Range("f2").Resize(tRow, 7) = DataTable

End Sub